/**
 * 
 */
package demo.tellurium.test.gbms;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import demo.tellurium.framework.BaseTelluriumJUnitTestCase;
import demo.tellurium.module.gbms.GBMSHomeModule;
import demo.tellurium.module.gbms.GBMSLeftNav;
import demo.tellurium.module.gbms.GBMSLoginModule;
import demo.tellurium.module.gbms.GBMSRunReportsModule;

/**
 * @author roger.xu
 * 
 */
public class RunReportsJUnitTestCase extends BaseTelluriumJUnitTestCase {
    private static GBMSHomeModule gbmsHome;
    private static GBMSLoginModule gbmsLogin;
    private static GBMSRunReportsModule gbmsRunReportsModule;

    @BeforeClass
    public static void initUi() {
        gbmsHome = new GBMSHomeModule();
        gbmsHome.defineUi();

        gbmsLogin = new GBMSLoginModule();
        gbmsLogin.defineUi();

        gbmsRunReportsModule = new GBMSRunReportsModule();
        gbmsRunReportsModule.defineUi();
    }

    @Before
    public void waitDelay() {
        waitingDelay();
    }

    @Test
    public void connectTo() {
        String contextUrl = getProperty("gbms.context.url");
        String pagePath = getProperty(GBMSHomeModule.PATH_KEY);
        String url = String.format("%s/%s", contextUrl, pagePath);
        connectUrl(url);
    }

    @Test
    public void testToSignInPage() {
        console.debug("[testToSignInPage]");
        gbmsHome.doClickSignInButton();
    }

    @Test
    public void testLogin() {
        console.debug("[testLogin]");
        String username = getProperty("gbms.admin.username");
        String password = getProperty("gbms.admin.password");
        gbmsLogin.doLogin(username, password);
    }

    @Test
    public void testToRunReportPage() {
        console.debug("[testToRunReportPage]");
        gbmsHome.doSelectRole(GBMSHomeModule.ROLE_DEV);
        gbmsHome.doClickLeftNav(GBMSLeftNav.RUN_REPORTS.getUid());
    }

    @Test
    public void testRunReport() {
        pauseSec(3);
        for (int i = 0; i < 1; i++) {
            run();
        }
    }

    private void run() {
        console.debug("[run]");
        gbmsRunReportsModule.doSelectComboBox("RunReportsType", 1);
        gbmsRunReportsModule.doSelectComboBox("Report", 4);
        // gbmsRunReportsModule.doSelectComboBox("Division", 2);
        gbmsRunReportsModule.doSelectComboBox("Type", 2);
        // gbmsRunReportsModule.doSelectComboBox("IPD", 2);
        gbmsRunReportsModule.doSelectComboBox("State", 2);
        gbmsRunReportsModule.doSelectComboBox("Translation", 2);
        pauseSec(1);
    }
}
